package com.example.demo.dao;


import com.example.demo.entity.Category;
import com.example.demo.entity.Product;
import com.example.demo.entity.Product_picture;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author liuxianchun
 * @date 2021/1/18
 */
@Repository
public interface ProductDao {

    @Select("select categoryId categoryId, categoryName categoryName from category")
    List<Category> getCategory();

    @Select("select * from product where status=1")
    List<Product> getAllProduct();

    @Select("select * from product_picture where productId=#{productId}")
    List<Product_picture> getDetailsPicture(int productId);

    @Select("select * from product where productId=#{productId}")
    Product getProductByID(int productId);

    @Select("select p.* from product p,secgoods sec where sec.productId=p.productId and sec.id=#{secgoodId}")
    Product getProductBySecID(int secgoodId);

    @Select("select categoryId from category")
    List getCategoryId();

    @Select("select * from product where categoryId=#{categoryID} and status=1 order by productSales desc limit #{currentPage},#{pageSize}")
    List<Product> getProductByCategory(int categoryID, int currentPage, int pageSize);

    @Select("select p.* from product p,category c where p.categoryId=c.categoryId and c.categoryName=#{categoryName} and p.status=1")
    List<Product> getProductByCategoryName(String categoryName);

    @Select("select * from product where status=1 and productName like '%${search}%' or productTitle like '%${search}%' or productIntro like '%${search}%'")
    List<Product> getProductBySearch(String search);

    @Select("select productSales from product where productId=#{productId}")
    Integer getSales(int productId);

    @Update("update product set productSales=productSales+#{sales} where productId=#{productId}")
    void updateSales(int productId,int sales);
}
